package solution;

import java.util.Scanner;

/**
 * Created by wangxingsheng on 2022/6/21.
 * 输出单向链表中倒数第k个结点
 */
public class LinkDesSortCount {
    private static class ListNode {
        int key;
        ListNode next;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int count = in.nextInt();
            ListNode head = new ListNode();
            ListNode p = head;
            for (int i = 0; i < count; i++) {
                ListNode node = new ListNode();
                node.key = in.nextInt();
                p.next = node;
                p = p.next;
            }
            int n = in.nextInt();
            deal(head, n);
        }
    }

    private static void deal(ListNode head, int n) {
        ListNode p = head;
        ListNode kp = null;
        int c = 0;
        while (p.next != null) {
            p = p.next;
            c++;
            if (c == n) {
                kp = head.next;
            }else if(c > n){
                kp = kp.next;
            }
        }
        if (kp != null) {
            System.out.println(kp.key);
        }
    }
}
